using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestPlatform.TestHost;
using Newtonsoft.Json;

namespace KAs.Test;

public class UnitTest1
{
    private readonly HttpClient _testClient;

    public UnitTest1()
    {
        _testClient = new TestServer(WebHost
                .CreateDefaultBuilder()
                .ConfigureServices((context, builder) =>
                {
                    builder.ConfigureServices(context.Configuration);
                })
                .Configure((context, builder) =>
                {
                    builder.Configure(context.HostingEnvironment, builder.ApplicationServices);
                }))
            .CreateClient();
        //_testClient.BaseAddress = new Uri("http://localhost:9527");
    }

    [Theory]
    [InlineData("api/tool/CheckHealth")]
    public async Task Get_EndpointsReturnSuccessAndCorrectContentType(string url)
    {
        // Act
        var response = await _testClient.GetAsync(url);

        // Assert
        response.EnsureSuccessStatusCode(); // Status Code 200-299
        Assert.Equal("text/html; charset=utf-8",
            response.Content.Headers.ContentType.ToString());
    }
}